//--------------------------------------------------------------------------------------------------------------------
// register the functions
var newRegistery1 = new Array( "getBetroomsToPlay", "fillBetroomToPlayPickList" );
var newRegistery2 = new Array( "getBetroomsToAdmin", "fillBetroomToAdminPickList" );
var newRegistery3 = new Array( "getBetroomsBeingLaunched", "fillBetroomBeingLaunchedPickList" );
allJsonsRegistry = allJsonsRegistry.concat(newRegistery1);
allJsonsRegistry = allJsonsRegistry.concat(newRegistery2);
allJsonsRegistry = allJsonsRegistry.concat(newRegistery3);  


//--------------------------------------------------------------------------------------------------------------------
// this function fills the pick list with the betroom
function fillBetroomPickList(betroomList, pickListName )
{
    // create reference to first select
    sel1 = document.getElementById(pickListName);

    //get the total item from the dropDownList   
    var intTotalItems = sel1.options.length;

    //loop through the number of items and remove them
    for(var intCounter=intTotalItems;intCounter>=0;intCounter--)
    {
        sel1.remove(intCounter);
    }

    // create the text which indicate what do the option
    sel1.options[sel1.length++] = new Option("Pick up betroom", "Pick up betroom");


   
    // fill the first dropdown uninvested stategies
     for (var i = 0; i < betroomList.betrooms.length; i++)
     {
        var betroomName = betroomList.betrooms[i].name;
        sel1.options[sel1.length++] = new Option( betroomName, betroomName );
     }
};

//--------------------------------------------------------------------------------------------------------------------
// this function fills the pick list with the betroom the user plays in
function fillBetroomToPlayPickList(betroomList)
{
    fillBetroomPickList(betroomList, "betroomToPlayDropList");
};

//--------------------------------------------------------------------------------------------------------------------
// this function fills the pick list with the betroom the user administrates
function fillBetroomToAdminPickList(betroomList)
{
    fillBetroomPickList(betroomList, "betroomToAdminDropList");
};

//--------------------------------------------------------------------------------------------------------------------
// this function fills the pick list with the betroom the user administrates
function fillBetroomBeingLaunchedPickList(betroomList)
{
    fillBetroomPickList(betroomList, "betroomBeingLaunchedDropList");
};

//--------------------------------------------------------------------------------------------------------------------
// this log the user into the specified bet room and go to the betrooms page
function goToSelectedBetroom(dropListNameWithBetroomName, nextLocation)
{
    betroomToEnter = document.getElementById(dropListNameWithBetroomName);
    var args = { 
      type: "POST", 
      url: "/enterBetroom/",
      cache: false,
      data: { 'betroom' : betroomToEnter.value }, 
      complete:function(res) { document.location.href = nextLocation; },
      error: function(errorThrown)  { document.write(errorThrown.responseText);  }  
    };
    $.ajax(args);
    return false;  
};



